clear
clear matrix
set more off

* ------------------------------------------------------------------------------
* set paths
global root "[include file path here]"
global input "$root/Input"
global output "$root/Output"
global intermediate "$root/Intermediate"
global figures "$root/Figures"

set more off
* ______________________________________________________________________________
* FIGURE 1A
use "$input/eventStudyPanel_raw.dta", clear
keep if conversions == 0 | (conversions == 1 & wg == "SF")
duplicates drop pid, force

gen hypothetical = 2014 if inrange(_n, 1, 1072)
local yti "number of conversions"

hist event_year if wg=="SF" & inrange(event_year,1999,2013), ///
freq discrete gap(20) color(none) xti("") yti("`yti'") lstyle(none) ///
xlab(1999(2)2013) lc(gs0) ylab(, nogrid) graphregion(color(white)) legend(off)
graph export "$figures/figure_1a.pdf", replace

* ______________________________________________________________________________
* FIGURE 1B
use "$input/eventStudyPanel_raw.dta", clear
keep if conversions == 0 | (conversions == 1 & wg == "SF")
duplicates drop pid, force

* cummulative plot and average conversion size
collapse (count) nconv = conv_sqft nrebate = tot_rebated ///
(mean) meanconv = conv_sqft  ///
(sd) sdconv = conv_sqft ///
(semean) seconv = conv_sqft ///
(min) minconv=conv_sqft ///
(max) maxconv = conv_sqft, by(event_year)

sort event_year
la da "collapsed data: conversion count, size, rebate by enrollment year"
save "$intermediate/savings_avgBYenrollYear.dta", replace

* read in collapsed dataset
use "$intermediate/savings_avgBYenrollYear.dta", clear

local yti "number of conversions"
local yti2 "average area converted [ft{sup:2}]"

* mean converted area
gr tw sc meanconv event_year if event_year>=2000, c(l) m(h) mc(gs0) lc(gs0) ///
ytitle("`yti2'") xtitle("") xlabel(2000(2)2014) ylabel(, nogrid) ///
graphregion(color(white)) xsize(8) ysize(5)
graph export "$figures/figure_1b.pdf", replace



* ==================== DONE DONE DONE ==================== *
